using UnityEditor;
using System.IO;

namespace IFramework
{
    public class FormatIFrameWorkScript
    { 
        public static string NewScriptName { get { return newScriptName; } set { newScriptName = value; } }
        public static string OriginScriptPath { get { return originScriptPath; } set { originScriptPath = value; } }
        private static string newScriptName = "newScript.cs";
        private static string originScriptPath = FrameWorkInfo.GetFrameWorkEditorPath().CombinePath(@"CopyAsset/CSharpScript.txt");

        [MenuItem("Assets/IFramework/CSharpScript")]
        public static void CreateUIBase()
        {
            CreateOriginIfNull();
            CopyAsset.CopyNewAsset(newScriptName, originScriptPath);
        }

        private static  void CreateOriginIfNull()
        {
            if (File.Exists(OriginScriptPath)) return;
            using (FileStream fs = new FileStream(originScriptPath, FileMode.Create, FileAccess.Write))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    fs.Lock(0, fs.Length);
                    sw.WriteLine("/*********************************************************************************");
                    sw.WriteLine(" *Author:         #FAuthor#");
                    sw.WriteLine(" *Version:        #FVERSION#");
                    sw.WriteLine(" *UnityVersion:   #FUNITYVERSION#");
                    sw.WriteLine(" *Date:           #FDATE#");
                    sw.WriteLine(" *Description:    #FDescription#");
                    sw.WriteLine(" *History:        2018.11--");
                    sw.WriteLine("*********************************************************************************/");
                    sw.WriteLine("namespace #FNameSpace#");
                    sw.WriteLine("{");
                    sw.WriteLine("\tpublic class #FSCRIPTNAME#");
                    sw.WriteLine("\t{");
                    sw.WriteLine("\t");
                    sw.WriteLine("\t}");
                    sw.WriteLine("}");
                    fs.Unlock(0, fs.Length);
                    sw.Flush();
                    fs.Flush();
                }
            }
            AssetDatabase.Refresh();
        }
    }

}